﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace DalEx
{
    public class BaoMingEx : Dal.BaoMingDal
    {
        public static int Insert(Model.BaoMing baoMing, ref string strResult)
        {
            int iResult = 0;
            DataSet ds = DalEx.BaoMingEx.Select(" and IdCardNo='" + baoMing.IdCardNo + "'");
            if (SqlHelper.HasRow(ds))
            {
                strResult = "抱歉，该儿童已经报名过，请耐心等待录取通知！";
            }
            else
            {
                iResult = DalEx.BaoMingEx.Insert(baoMing);
                strResult = iResult > 0 ? "报名数据已提交，请耐心等待录取通知！" : "报名数据未能保存，请联系我们！";
            }
            return iResult;
        }

        public static int Delete(string strQuery, ref string strResult)
        {
            int iResult = 0;
            DataSet ds = DalEx.BaoMingEx.Select(strQuery);
            Model.BaoMing baoMing = null;
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                baoMing = new Model.BaoMing(dr);
                iResult += Dal.BaoMingDal.Delete(baoMing.Id);
            }
            strResult = iResult > 0 ? "数据删除成功！" : "数据不存在无法删除";
            return iResult;
        }
        public static bool UpdateStatus(int iSelectId,int iStatus,string strCheckInfos)
        {
            bool bResult = false;
            Model.BaoMing baoMing = DalEx.BaoMingEx.Select(iSelectId);
            if (baoMing != null)
            {
                bResult = SqlHelper.ExecSql("update BaoMing set Status=" + iStatus + ",CheckInfos='" + strCheckInfos + "' where Id=" + iSelectId) > 0;
            }
            return bResult;
        }
        public static bool UpdateStatus(int iSelectId, int iStatus,string strClassNum,int iClassNo, string strCheckInfos)
        {
            bool bResult = false;
            Model.BaoMing baoMing = DalEx.BaoMingEx.Select(iSelectId);
            if (baoMing != null)
            {
                bResult = SqlHelper.ExecSql("update BaoMing set Status=" + iStatus + ",ClassNum='" + strClassNum + "',ClassNo='" + iClassNo + "',CheckInfos='" + strCheckInfos + "' where Id=" + iSelectId) > 0;
            }
            return bResult;
        }
    }
}
